<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>比较对象是否相等问题</title>
</head>
<script>
  var obj1 = {//调完接口，数据存入变量，保存
    name: '小明',
    year: 14,
    sex: '男',
    weight: '56kg'
  }
  // var obj2 = {//双向绑定，页面中的数据
  //   name:'小明',
  //   year:14
  //   sex:'男',
  //   weight:'56kg',
  //   // pkId:'1007434939716079616phshzz',
  // }
  var object1 = JSON.parse(JSON.stringify(obj1));
  var object2 = JSON.parse(JSON.stringify(obj1)); 
  object2.sex = '女'
  object2.name = '王大锤'
  console.log(object1,object2);
  // function shallowEqual(object1, object2) {
  //   const keys1 = Object.keys(object1);
  //   const keys2 = Object.keys(object2);
  //   if (keys1.length !== keys2.length) {
  //     return false;
  //   }
  //   for (let index = 0; index < keys1.length; index++) {
  //     const val1 = object1[keys1[index]];
  //     const val2 = object2[keys2[index]];
  //     if (val1 !== val2) {
  //       return false;
  //     }
  //   }
  //   return true;
  // }
  // shallowEqual(object1,object2)
  for (const key in object1) {
    if(object1[key] !== object2[key]){
      console.log(key,'-------------------不同');
    }
  }
</script>

<body>
  <div>222222222222222</div>
</body>

</html>